﻿$(function () {

    var countryInput = $('input[name$=txtCountry]');
    var countryValue = $('<input type="hidden" />').attr('name', countryInput.attr('name') + '_value');
    countryInput.after(countryValue);

    countryInput.autocomplete({
        source: countries,
        mustMatch: true,
        autoFill: true,
        delay: 10,
        select: function (event, ui) {
            $('input[name$=txtCountry]').val(ui.item.label);
            $('input[name$=txtCountry_value]').val(ui.item.value);
            return false;
        },
        focus: function (event, ui) {
            $('input[name$=txtCountry]').val(ui.item.label);
            return false;
        }
    });
});